package Q2;

import java.util.Scanner;

public class Main {

    public static boolean flag1;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int count = 0;
        for (int i = a; i <= b; i++) {
            String str = i + "";
            char[] ch = str.toCharArray();
            int len = ch.length;
            boolean[] flag = new boolean[len];

            dfs(ch, flag, new StringBuilder(), 0);

            if (flag1) {
                count++;
            }
            flag1 = false;
        }

        System.out.println(count);

    }

    public static void dfs(char[] ch, boolean[] flag, StringBuilder stringBuilder, int count) {
        if (count == 2) {
            int num = Integer.parseInt(stringBuilder.toString());
            if ((num + "").length() == 2) {
                if (isPrime(num)) {
                    flag1 = true;
                }
            }

            return;
        }

        for (int i = 0; i < ch.length; i++) {
            if (!flag[i]) {
                flag[i] = true;
                stringBuilder.append(ch[i]);
                dfs(ch, flag, stringBuilder, count + 1);

                //回溯
                flag[i] = false;
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            }
        }
    }

    public static boolean isPrime(int num) {
        if (num == 2) {
            return true;
        }

        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }

        return true;
    }
}
